<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2017/8/27
 * Time: 0:26
 */
namespace app\admin\controller\active;

use app\admin\model\StaffCard;
use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;

class Activelist extends Backend{
    protected
    $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $statuslist=db('active_status')->select();
        $this->model = model('orderactive');
        $this->view->assign("statuslist",$statuslist);
    }

    public function index($id=null)
    {
        /**
         * 如果为ajax提交，则返回相应json数据
         */
        $this->view->assign("active_id",$id);
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model->with('activestatus')->where('active_id',$id)
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model->with('activestatus')->where('active_id',$id)
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }

    /**
     * 重载父类
     */
    public function add($id=null)
    {
        $this->view->assign("active_id",$id);
        return parent::add();
    }
}
